<template>
  <a-spin :spinning="loading">
    <BaseAudit
      ref="baseAudit"
      :callback-fn="callbackFn"
    >
      <template slot="extraOption" v-if="taskDefKey == 'XMFJL' || taskDefKey == 'SWJL' || taskDefKey == 'CWZG'">
          <title-name title="会签意见"></title-name>
          <custom-form
            ref="customForm"
            :is-validate="true"
            :edit-model="'E'"
            :is-emit="false"
            :formList="formList"
            :form="form"
            :rules="{}"
          ></custom-form>
      </template>
    </BaseAudit>
  </a-spin>
</template>

<script>

import { updateByProcess } from '@/api/businessAffairs/addListContract' // api
import BaseAudit from '@/views/matters/approval/components/BaseAudit'
export default {
    name: 'AddListContractAudit',
    components: {
        BaseAudit
    },
    data() {
        return {
            loading: false,
            form: {},
            type: null,
            editModel:-1,   // 代表查看
        }
    },
    computed: {
      taskDefKey() {
        return this.$route.query.taskDefKey
      },
      formList() {
        // @ApiModelProperty(name = "buildPosition" , value = "施工部位（范围、轴线、标高）")
        // private String buildPosition;
        // @ApiModelProperty(name = "completeContent" , value = "施工完成内容及工作量")
        // private String completeContent;
        // @ApiModelProperty(name = "contractProjectQuantity" , value = "合同工程量")
        // private String contractProjectQuantity;
        // @ApiModelProperty(name = "actualComplete" , value = "实际完成工程量初审值")
        // private String actualComplete;
        // @ApiModelProperty(name = "summationPaid" , value = "累计已付工程款金额")
        // private String summationPaid;
        let listMap = {
          XMFJL: [
            {
              keyName: 'buildPosition',
              type: 'BaseTextarea',
              label: '施工部位（范围、轴线、标高）',
              disabled: !!this.editModel,
              span: 24,
              rules: [{ required: true, message: '请输入' }],
              attrs: {
                // maxLength: 300
              }
            },
            {
              keyName: 'completeContent',
              type: 'BaseTextarea',
              label: '施工完成内容及工作量',
              disabled: !!this.editModel,
              span: 24,
              rules: [{ required: true, message: '请输入' }],
              attrs: {
                // maxLength: 300
              }
            },
          ],
          SWJL: [
            {
              keyName: 'contractProjectQuantity',
              type: 'BaseTextarea',
              label: '合同工程量',
              span: 24,
              rules: [{ required: true, message: '请输入' }],
              attrs: {
                // maxLength: 300
              }
            },
            {
              keyName: 'actualComplete',
              type: 'BaseTextarea',
              label: '实际完成工程量初审值',
              span: 24,
              rules: [{ required: true, message: '请输入' }],
              attrs: {
                // maxLength: 300
              }
            },
          ],
          CWZG: [
            {
              keyName: 'summationPaid',
              type: 'BaseTextarea',
              label: '累计已付工程款金额',
              span: 24,
              rules: [{ required: true, message: '请输入' }],
              attrs: {
                // maxLength: 300
              }
            },
          ]
        }
        return listMap[this.taskDefKey] || []
      },
      rules() {
        const obj = {}
        this.formList?.map((item) => {
          if (item.rules) {
            obj[item.keyName] = item.rules
          }
        })
        return obj
      }
    },
    created() {
    },
    mounted() {
      console.log(this.$route.query,'this.$route.query')
      this.editModel = this.$route.query.editModel;
    },
    methods: {
      validate() {
        let flag = true
        let keys = {
          XMFJL: ['buildPosition', 'completeContent'],
          SWJL: ['contractProjectQuantity', 'actualComplete'],
          CWZG: ['summationPaid'],
        }[this.taskDefKey] || []
        keys.forEach((v) => {
          if (!this.form[v]) {
            flag = false
          }
        })
        return flag
      },
      callbackFn(type) {
        let flag = true
        this.type = type
        
        if (type == 'approval') {
          if(!this.validate()) {
            this.$warning({ content: '请填写会签意见' })
            flag = false
            return flag
          }
        }
        let param = {
          id: this.$route.query.id,
          ...this.form
        }
        return updateByProcess(param).then((res) => {
          flag = res?.code == 0
          console.log(flag)
          return flag
        }).catch(() => {
          return false
        })
      }
    }
}
</script>

<style lang='less' scoped>
</style>